<template>
  <div>
    <div class="top">
      <span class="fh"><van-icon name="arrow-left" @click="fh" /></span>
      <span class="zc">注册</span>
      <span class="dl" @click="dl">登录</span>
    </div>
    <div class="mainCenter">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="手机号/账户名/邮箱"
          :rules="[{ required: true, message: '请填写用户名' }]"
          class="yhm"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
          class="yhm"
        />
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            @click="submit"
            >提交</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
export default {
  name: "Register",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    onSubmit(values) {
      let tel = this.username;
      // console.log('tel: ', tel);
      let psd = this.password;
      // console.log(' psd: ', psd);
      this.$service
        .post("/api/user/dofinishregister", {
          tel,
          password: psd,
        })
        .then(res => {
          console.log(res, "res");
          if (res.data.code == 200) {
            Toast("注册成功");
          }
        })
        .catch((err) => {
          Toast("注册失败");
        });
      console.log("submit", values);
    },
    fh() {
      this.$router.go(-1);
    },
    dl() {
      this.$router.push("/Login");
    },
    submit() {},
  },
  /* created() {
    this.getRanCode();
    axios({
      url: "http://localhost:3000/person",
      method: "post",
      data: `username=${this.username}&userpass=${this.userpass}`,
    }).then((res) => {
      if (res.data) {
        console.log(res.data);
        this.msg = "注册成功";
      } else {
        this.msg = "注册失败";
      }
      //  this.msg = "";
    });
  }, */
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}
.top {
  height: 3rem;
  text-align: center;
  line-height: 3rem;
  border-bottom: 2px solid gray;
  position: relative;
}
.fh {
  position: absolute;
  font-size: 20px;
  left: 1rem;
}
.yhm {
  height: 4rem;
  line-height: 4rem;
  margin-bottom: 1rem;
}
.dl {
  position: absolute;
  right: 0.5rem;
}
</style>